<?php
class ml_biz_user_feed{

    private $_data=array();//被处理的数据
    private $_nicks=array();//nick集合
    private $_uids=array();//uid集合
    private $_rids=array();//资源id集合
    private $_quote=array();//被引用的数据
    private $_nickname=array();//被查看人的昵称
    private $_cnt_comment=array();//评论数
    private $_feed_rids=array();//feed资源id
    /**
     * @fileoverview
     * @data         碎碎念所需数组，可以各种类型的
     * @uid             所有涉及nick的uid集合
     * @copyright     是否是自己
     */
    public function get_html($data=array(),$uid,$ifme){
        if(empty($data))
        return false;
        $this->_data=$data;
        $this->_uids=$uid;
        $this->fen();
        $this->getUids();
        $this->getNick();
        $this->get_cnt();
        $this->he();

        return  ml_tool_feedOutput::parseFeed($this->_data,$ifme);//模版赋值

    }

    private function getNick()
    {
        $this->_nicks = ml_tool_nick::uids2nicks($this->_uids);

        //        $oAccount = new ml_model_dbUserAccount();
        //        $rs = $oAccount->getNicksByUids($this->aUid);
        //        $this->aNicks = $oAccount->get_data();
    }
    private function get_cnt()
    {

        $oRedis = new ml_model_rdsCount();
        $rs = $oRedis->getCommentCount($this->_feed_rids);
        /**
         * @todo
         */
        $this->_cnt_comment = $oRedis->get_data();


    }
    /**
     * @fileoverview    这块加个for把引用到的内容的uids得到，然后得到nicks然后赋给引用数组
     *
     */
    private function getUids(){
        if(is_array($this->_quote))
        foreach ($this->_quote as $contentValue) {
            $this->_uids[]=$contentValue['uid'];
        }
    }
    /**
     * @fileoverview    拆feed数据，获取扩展数据
     *
     */
    private function fen(){

        foreach ($this->_data as &$fen) {
            
            switch ($fen['type']) {
                case ML_FEED_TYPE_ATTITUDE:
                case ML_FEED_TYPE_REPOST_SHORT:
                case ML_FEED_TYPE_REPOST_PIC:    
                case ML_FEED_TYPE_REPOST_COLLECTION:
                    $this->_rids[]=$fen['feed_info']['rid'];
                case ML_FEED_TYPE_PUB_DOTEY:
                    $fen['is_pic'] = false;
                    break;
                case ML_FEED_TYPE_PUB_PIC:
                    $fen['is_pic'] = true;
                    break;
                    
            }
            $this->_feed_rids[]=$fen['rid'];    
        }
        $this->_feed_rids=array_merge($this->_feed_rids,$this->_rids);
        $modelContent=new ml_model_dbContent();
        $this->_quote=$modelContent->get_content_by_rids($this->_rids);

    }
    /**
     * @fileoverview    合并feed数据,加上昵称，content
     *
     */
    private function he(){

        foreach ($this->_data as &$he) {
            
            if ($he['type']==ML_FEED_TYPE_ATTITUDE||$he['type']==ML_FEED_TYPE_REPOST_SHORT||$he['type']==ML_FEED_TYPE_REPOST_COLLECTION){//后期加上各种转发
                $quote=$this->_quote[$he['feed_info']['rid']];
                if(empty($quote)){
                $he['quote']['isnull']=true;
                }
                else{
                $he['quote']=$quote;
                $he['quote']['isnull']=false;                        
                }                
                $he['quote']['nick']=$this->_nicks[$he['quote']['uid']];
                $he['quote']['cnt']=$this->_cnt_comment[$he['feed_info']['rid']];
            }
            
            $he['nick']=$this->_nicks[$he['uid']];
            $he['cnt']=$this->_cnt_comment[$he['rid']];
            
        }
            
    }
}
?>